const Koa = require("koa2");
const app = new Koa();
const router = require("./router");
const cors = require("koa2-cors");
const swagger = require("./swagger/swagger");
const koaSwagger = require("koa2-swagger-ui");
app.use(
  cors({
    origin: "*",
  })
);

app.use(async (ctx, next) => {
  const time0 = new Date().getTime();
  await next();
  console.log(`${ctx.url} ${ctx.method} ${new Date().getTime() - time0}ms`);
});

app.use(swagger.routes(), swagger.allowedMethods());
app.use(
  koaSwagger({
    routePrefix: "/swagger", // host at /swagger instead of default /docs
    swaggerOptions: {
      url: "/swagger.json", // example path to json
    },
  })
);

app.use(router.routes());
app.listen("3000", () => {
  console.log("Listening port :3000,click " + "http://localhost:3000");
});
